<?php
/**
 * Created by PhpStorm.
 * User: wodrow
 * Date: 2018/9/12
 * Time: 15:42
 */

namespace console\modules\others\controllers;


use common\components\tools\Api;
use common\components\tools\Excel;
use common\components\tools\Model;
use common\components\wodrow\phpSpreadsheet\src\phpSpreadsheet\Helper;
use common\models\BaiRongValidateLog;
use common\models\FicoEarlyWarning;
use common\models\credit_app\OrderCert;
use yii\console\Controller;
use yii\db\Exception;

class OtherController extends Controller
{
    /**
     * php yii others/other/import-excel $path
     * @param $path
     */
    public function actionImportExcel($path)
    {
        $data = Helper::newSpreadsheet($path)->getRows();
        $data = Excel::excelDataMap($data);
        foreach ($data as $k => $v){
            $resp = Api::request('/big_data/validate/fico-score', [
                'mobile' => $v['客户手机号'],
                'idcard' => $v['身份证'],
                'other_data' => json_encode($v),
                'import_type' => FicoEarlyWarning::IMPORT_TYPE_EXCEL,
            ]);
            var_dump($resp->content);
            $resp = Api::request('/big_data/validate/bairong-validate', [
                'br_conf' => 'bairong0',
                'name' => $v['客户姓名'],
                'mobile' => $v['客户手机号'],
                'idcard' => $v['身份证'],
                'other_data' => json_encode($v),
                'import_type' => BaiRongValidateLog::IMPORT_TYPE_EXCEL,
            ]);
            var_dump($resp->content);
        }
    }

    /**
     * php yii others/other/check-br
     * 新系统查询百融
     * @param string $br_conf
     * @throws Exception
     */
    public function actionCheckBr($br_conf = 'bairong0')
    {
        $cert_ids = [152253, 152254, 152255, 152256, 152257, 152259, 152260, 152261, 152262, 152263, 152264, 152265, 152266, 152267, 152268, 152269, 152272, 152273, 152274, 152275, 152276, 152277, 152278, 152279, 152280, 152281, 152282, 152283, 152284, 152285, 152286, 152287, 152288, 152289, 152290, 152291, 152292, 152293, 152294, 152296, 152297, 152300, 152301, 152302, 152303, 152304, 152306, 152307, 152308, 152309, 152310, 152311, 152312, 152313, 152314, 152316, 152317, 152318, 152320, 152321, 152322, 152324, 152325, 152326, 152328, 152329, 152331, 152332, 152333, 152334, 152335, 152336, 152337, 152338, 152339, 152340, 152341, 152342, 152343, 152346, 152347, 152348, 152349, 152350, 152351, 152352, 152353, 152354, 152355, 152356, 152357, 152359, 152360, 152361, 152363, 152364, 152365, 152366, 152367, 152369, 152370, 152371, 152372, 152373, 152374, 152376, 152377, 152378, 152379, 152380, 152381, 152382, 152383, 152384, 152385, 152388, 152389, 152390, 152391, 152392, 152394, 152395, 152396, 152397, 152398, 152399, 152400, 152401, 152402, 152403, 152404, 152405, 152406, 152407, 152408, 152409, 152410, 152411, 152412, 152413, 152415, 152416, 152418, 152419, 152420, 152421, 152422, 152423, 152424, 152425, 152427, 152428, 152429, 152430, 152431, 152432, 152433, 152434, 152435, 152436, 152438, 152439, 152440, 152441, 152442, 152444, 152445, 152446, 152447, 152448, 152449, 152451, 152453, 152454, 152456, 152457, 152458, 152459, 152460, 152461, 152462, 152463, 152464, 152465, 152466, 152467, 152468, 152469, 152470, 152471, 152472, 152473, 152474, 152475, 152477, 152479, 152480, 152481, 152482, 152483, 152484, 152485, 152486, 152487, 152488, 152489, 152490, 152492, 152493, 152494, 152495, 152496, 152497, 152498, 152499, 152503, 152505, 152506, 152507, 152508, 152509, 152510, 152511, 152512, 152514, 152515, 152516, 152517, 152518, 152520, 152522, 152523, 152524, 152525, 152526, 152527, 152528, 152529, 152530, 152531, 152532, 152533, 152534, 152535, 152536, 152537, 152539, 152541, 152543, 152544, 152545, 152546, 152547, 152548, 152549, 152550, 152551, 152553, 152554, 152555, 152556, 152557, 152558, 152559, 152560, 152561, 152562, 152563, 152566, 152567, 152568, 152569, 152570, 152571, 152572, 152573, 152574, 152576, 152577, 152582, 152583, 152585, 152586, 152587, 152588, 152590, 152591, 152592, 152593, 152594, 152595, 152597, 152598, 152599, 152600, 152601, 152602, 152603, 152604, 152605, 152606, 152607, 152608, 152609, 152610, 152611, 152612, 152614, 152615, 152616, 152617, 152618, 152619, 152620, 152621, 152622, 152623, 152624, 152625, 152626, 152627, 152628, 152629, 152630, 152631, 152632, 152633, 152634, 152635, 152636, 152637, 152638, 152639, 152640, 152641, 152642, 152643, 152644, 152645, 152646, 152647, 152648, 152649, 152650, 152651, 152652, 152653, 152654, 152655, 152656, 152657, 152658, 152659, 152660, 152661, 152662, 152664, 152665, 152666, 152667, 152668, 152669, 152670, 152672, 152675, 152676, 152677, 152678, 152681, 152682, 152683, 152684, 152685, 152686, 152687, 152688, 152689, 152690, 152691, 152694, 152695, 152696, 152697, 152698, 152699, 152700, 152701, 152702, 152703, 152704, 152705, 152706, 152707, 152708, 152709, 152712, 152713, 152714, 152715, 152716, 152718, 152719, 152720, 152721, 152724, 152725, 152726, 152727, 152728, 152730, 152731, 152732, 152733, 152734, 152735, 152737, 152738, 152739, 152740, 152741, 152743, 152744, 152745, 152746, 152747, 152748, 152749, 152750, 152751, 152752, 152753, 152754, 152755, 152756, 152757, 152758, 152759, 152760, 152761, 152762, 152763, 152764, 152765, 152766, 152767, 152768, 152769, 152770, 152771, 152772, 152773, 152774, 152775, 152776, 152777, 152778, 152779, 152781, 152782, 152783, 152784, 152785, 152786, 152788, 152789, 152790, 152791, 152792, 152793, 152794, 152795, 152796, 152797, 152798, 152799, 152800, 152801, 152802, 152803, 152804, 152805, 152806, 152807, 152808, 152809, 152811, 152812, 152813, 152814, 152816, 152817, 152818, 152819, 152820, 152821, 152822, 152823, 152824, 152825, 152826, 152827, 152828, 152829, 152830, 152831, 152833, 152835, 152836, 152837, 152838, 152839, 152840, 152841, 152842, 152843, 152844, 152845, 152846, 152847, 152848, 152849, 152850, 152851, 152852, 152853, 152854, 152855, 152856, 152857, 152858, 152859, 152860, 152861, 152862, 152863, 152864, 152865, 152866, 152867, 152868, 152869, 152870, 152871, 152872, 152873, 152874, 152875, 152876, 152877, 152879, 152880, 152881, 152883, 152884, 152885, 152886, 152887, 152888, 152889, 152890, 152891, 152892, 152893, 152894, 152895, 152896, 152897, 152898, 152900];
        foreach ($cert_ids as $k => $v) {
            $cert = OrderCert::findOne($v);
            $resp = Api::request('/big_data/validate/bairong-validate', [
                'br_conf' => $br_conf,
                'name' => $cert->ct_name,
                'idcard' => $cert->ct_code,
                'mobile' => $cert->ct_mobile,
            ]);
            $content = $resp->content;
            $content_arr = json_decode($content, true);
            if (isset($content_arr['code'])&&$content_arr['code']==200){
                $data = $content_arr['data'];
                $cert->ct_bigdata = $data['optimize_show'];
                $cert->ct_bigdata_number = $data['swift_numbers']['detail_list'];
                $cert->ct_bigdata_org = '百融金服';
                if (!$cert->save()){
                    throw new Exception(Model::getModelError($cert));
                    exit;
                }else{
                    var_dump($cert->ct_id." -- ".$cert->ct_name.":".$cert->ct_bigdata);
                }
            }
        }
    }
}